<template>
  <div class="employee">
    <v-head :userName="userName"></v-head>
    <section class='section'>
        <div class="emp_section">
          <div class="emp_top">
            <emp-info class="emp_info" :srcImg="srcImg" :reportPlatform="reportPlatform" :leaderPortal="leaderPortal" :holidayPlatform="holidayPlatform" :urlTarget="urlTarget" :emplInfo="emplInfo"></emp-info>
            <emp-approval :tab.sync='tab1' :tabNumA="tab1Num" :tabNumR="tab2Num" class="emp_approval"></emp-approval>
          </div>
          <ul class="emp_lists">
            <li class="emp_item">
              <div class="contentList">
                <emp-list  :dataList="noticeList" title="任免信息" tabInfo="first"></emp-list>
              </div>
            </li>
            <li class="emp_item">
              <div class="contentList">
                <emp-list  :dataList="appointList" title="公示消息" tabInfo="second"></emp-list>
              </div>
            </li>
            <li class="emp_item">
              <div class="contentList border_none">
                <emp-recruit  :dataList="recruitList" title="招聘消息" tabInfo="third"></emp-recruit>
              </div>
            </li>
          </ul>
        </div>
    </section>
  </div>
</template>

<script>
//import Axios from "axios";
import Vue from "vue";
import { Tabs } from "element-ui";

import EmpInfo from '@/components/employee/empInfo'
import EmpApproval from '@/components/employee/EmpApproval'
import EmpList from '@/components/employee/EmpList'
import EmpRecruit from '@/components/employee/EmpRecruit'
import Head from '@/components/employee/header'

//const EmpInfo = r => require.ensure([],() => r(require('@/components/employee/empInfo')),'empInfo');
//const EmpApproval = r => require.ensure([],() => r(require('@/components/employee/EmpApproval')),'EmpApproval');
//const EmpList = r => require.ensure([],() => r(require('@/components/employee/EmpList')),'EmpList');
//const EmpRecruit = r => require.ensure([],() => r(require('@/components/employee/EmpRecruit')),'EmpRecruit');
//const Head = r => require.ensure([],() => r(require('@/components/employee/header')),'header');


Vue.use(Tabs);

export default {
  name: "employee",
  data() {
    return {
      emplInfo: [],
      appointList: [],
      noticeList: [],
      recruitList: [],
      tab1:[],
      tab2Num:0,
      tab1Num:0,
      userName:null,
      srcImg:null,
      urlTarget:'',
      reportPlatform:null,
      leaderPortal:null,
      holidayPlatform:null,

    };
  },
  methods: {
    getEmplid: function(keyToValue) {
      var url = window.location.search;
      if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        var strs = str.split("&");
        // var keys = [],values = [];
        for (var i = 0; i < strs.length; i++) {
          var splitKey = strs[i].split("=");
          if (keyToValue === splitKey[0]) {
            return splitKey[1];
            // break;
          }
        }
      }
    },
   	getWaitAppro:function(){
      let params = {
        pageNum: 1,
        pageSize: 2
      }
      this.Axios
        .Post(this.URL.AuditBylist.url, params)
        .then((res) => {
          this.tab1 = res.data.datas;
          this.tab1Num = res.data.total || 0;
				
        })   		
   	},
   	getDoneAprro:function(){
       let params = {
        pageNum: 1,
        pageSize: 2,
        status:1,
      }
      this.Axios
        .Post(this.URL.findCopyToMeFlow.url, params)
        .then((res) => {
          this.tab2 = res.data.datas;
          this.tab2Num = res.data.total || 0;
          
        })
  		
   	},
   	
   	
   	initAjaxS:function(){


            this.Axios.Post(this.URL.queryList.url, {}).then(res => {
              this.appointList = res.data.datas.appointList; // 任免列表
              this.noticeList = res.data.datas.noticeList; // 公示列表
              this.recruitList = res.data.datas.recruitList; // 招聘列表
            });
        
            // 查看员工信息
            this.Axios.Post(this.URL.getEmployeeDetail.url).then(res => {
              this.emplInfo = res.data.datas.info[0]; // 员工信息
            });


						//获取审批详情
						this.getWaitAppro();
						this.getDoneAprro();

   	}
  },
  beforeCreate(){

	
  },
  created() {

   
	   if (location.hash.split('?').length>1) {
	   	
	   		 localStorage.clear();
	   	   var params = {};
	   	   var arr = location.hash.split('?')[1].split('&');
			   arr.forEach(function(val,index,arr){
			       var keyArr = val.split('=');
			       var key = keyArr[0];
			       var value = keyArr[1];
			       params[key] = value;
			   });
			   params.url = 'https://m2.cmhk.com/PSP/sso';
			   
   			 localStorage.setItem('para',JSON.stringify(params));
    
    
    
			    this.Axios.Post(this.URL.loginProduct.url,params).then(res=>{
			        
			        if (res.data.status === 1) {
			            	
    	
			        		
			            var name = res.data.datas.user.username;
			            var id = res.data.datas.user.userid;
			            var token = res.data.token;
			            var ldmh = res.data.ldmh;
			            
			            
			            
			            this.leaderPortal = res.data.datas.leaderPortal;
			            this.reportPlatform = res.data.datas.reportPlatform;
			            this.holidayPlatform = res.data.datas.holidayPlatform;
			            this.userName = name;
			            
			       
			            localStorage.setItem('userName',name);
			            localStorage.setItem('token',token);
			            localStorage.setItem('leaderPortal',this.leaderPortal );
			            localStorage.setItem('reportPlatform',this.reportPlatform);
			            localStorage.setItem('holidayPlatform',this.holidayPlatform);
			
									
									//获取图片
									this.srcImg = this.Axios.baseURI + this.URL.getLoginUserImg.url + "?token=" + token;  									
									
									this.initAjaxS();
		
			
			
			        } 
			
			
			    })	
			   
			   
	   } else {

					this.initAjaxS();
  
          if (localStorage.getItem('leaderPortal')) {
              this.leaderPortal =   Number(localStorage.getItem('leaderPortal'));
          }
          if (localStorage.getItem('reportPlatform')) {
              this.reportPlatform =   Number(localStorage.getItem('reportPlatform'));
          }
		    	if (localStorage.getItem('userName')) {
              this.userName = localStorage.getItem('userName');
          }
		    	if (localStorage.getItem('holidayPlatform')) {
              this.holidayPlatform = Number(localStorage.getItem('holidayPlatform'));
          }		      

					//获取图片
					this.srcImg = this.Axios.baseURI + this.URL.getLoginUserImg.url + "?token=" + localStorage.getItem('token');  
	   }

    
 
		

    
    

	

    // this.Axios.Post(this.URL.queryList.url, {}).then(res => {
    //   this.appointList = res.data.datas.appointList; // 任免列表
    //   this.noticeList = res.data.datas.noticeList; // 公示列表
    //   this.recruitList = res.data.datas.recruitList; // 招聘列表
    // });

    // // 查看员工信息
    // this.Axios.Post(this.URL.getEmployeeDetail.url).then(res => {
    //   this.emplInfo = res.data.datas.info[0]; // 员工信息
    // });



    
  },
  components: {
    EmpInfo,
    EmpApproval,
    EmpList,
    EmpRecruit,
    "v-head": Head
  },
  mounted() {}
};
</script>

<style scoped>
	html body{
		background-color: #ecf0f5;
	}	
	
	
.employee {
  width: 100%;
}
.section {
  margin-top: 50px;
}
.emp_head {
  height: 50px;
  background: #3c8dbc;
  line-height: 50px;
  text-align: center;
  color: #fff;
}
.emp_section {
  box-sizing: border-box;
  -moz-box-sizing: border-box; /* Firefox */
  -webkit-box-sizing: border-box; /* Safari */
  padding: 30px 50px;
  background: #ecf0f5;
}
.emp_top {
  overflow: hidden;
}
.emp_info {
  width: 66%;
  background: #fff;
  height: 310px;
  float: left;
}
.emp_approval {
  width: 33%;
  background: #fff;
  height: 310px;
  float: right;
}
.emp_lists {
  margin-top: 12px;
  overflow: hidden;
}
.emp_lists .emp_item {
  width: 33.3%;
  float: left;
  background: #fff;
  height: 360px;
}
.emp_lists .emp_item .contentList {
  margin: 20px 0;
  border-right: 1px solid #ecf0f5;
}
.emp_lists .emp_item .border_none {
  border-right: 0;
}
.emp_lists .emp_item .contentList >h2{
    font-size: 16px;
    margin:10px 0px -30px 30px;
}
</style>
<style>

	
</style>
<style>
	@charset "UTF-8";.el-message{box-shadow:0 2px 4px rgba(0,0,0,.12),0 0 6px rgba(0,0,0,.04);min-width:300px;padding:10px 12px;box-sizing:border-box;border-radius:2px;position:fixed;left:50%;top:20px;-ms-transform:translateX(-50%);transform:translateX(-50%);background-color:#fff;transition:opacity .3s,transform .4s;overflow:hidden}.el-message .el-icon-circle-check{color:#13ce66}.el-message .el-icon-circle-cross{color:#ff4949}.el-message .el-icon-information{color:#50bfff}.el-message .el-icon-warning{color:#f7ba2a}.el-message__group{margin-left:38px;position:relative;height:20px;line-height:20px;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center}.el-message__group p{font-size:14px;margin:0 34px 0 0;white-space:nowrap;color:#8391a5;text-align:justify}.el-message__group.is-with-icon{margin-left:0}.el-message__img{width:40px;height:40px;position:absolute;left:0;top:0}.el-message__icon{vertical-align:middle;margin-right:8px}.el-message__closeBtn{top:3px;right:0;position:absolute;cursor:pointer;color:#bfcbd9;font-size:14px}.el-message__closeBtn:hover{color:#97a8be}.el-message-fade-enter,.el-message-fade-leave-active{opacity:0;-ms-transform:translate(-50%,-100%);transform:translate(-50%,-100%)}
</style>
